<div class="nav">
    <a class="sel" href="{:U('index')}">发放优惠券</a>
</div>
<div class="add">
    <form method="post" action="" onsubmit="return checkform()" >
        <table class="table_add" cellpadding='8'>
            <tr>
                <td width="100px">发放范围</td>
                <td style="line-height:26px;">
                    <div><label><input type="radio" name="give_type" id="give_type1" value="all" checked="checked" > 所有会员</label></div>
                    <div><label><input type="radio" name="give_type" id="give_type2" value="level" > 按会员等级:</label>
                        <foreach name="level_sel" item="level_name" key="level_id">
                            <label><input type="checkbox" name="level_ids[]" value="{$level_id}" >{$level_name}</label>
                        </foreach>
                    </div>
                    <div><label><input type="radio" name="give_type" id="give_type3" value="single" > 指定会员：</label>
                        <textarea name="member_list" id="member_list" style="width:100%;height:60px; text-align:left;" /></textarea>
                        <label class="msg">输入会员手机，按英文逗号,分隔</label>
                    </div>
                    
                </td>
            </tr>
            <tr>
                <td>优惠券面值</td>
                <td style="line-height:26px;">
                    <input type="text" name="money" id="money" class="input1" style="width:50px" value="" /> 元
                </td>
            </tr>
                    <tr>
                <td>满多少使用</td>
                <td style="line-height:26px;">
                    <input type="text" name="cart_total" id="cart_total" class="input1" style="width:50px" value="0" /> 元 (以购物车价格计算)
                </td>
            </tr>
            <tr>
                <td>使用时间</td>
                <td style="line-height:26px;">
                    从 <input type="text" class="datetime" name="begin_time" readonly="readonly" onclick="WdatePicker({dateFmt: 'yyyy-MM-dd'})" id="begin_time" value="" /> 至 
                    <input type="text" onclick="WdatePicker({dateFmt: 'yyyy-MM-dd'})" readonly="readonly" class="datetime" name="end_time" id="end_time" value="" />
                </td>
            </tr>
            <tr>
                <td>发放原因</td>
                <td style="line-height:26px;">
                    <input type="text" name="remark" id="remark" class="input1" style="width:500px" value="" /><label class="msg">短信通知或者备注用</label>
                </td>
            </tr>
            <tr>
                <td></td>
                <td style="line-height:26px;"><input class="btn1" type="submit" value="提交" /></td>
            </tr>
        </table>
    </form>
</div>
<script type="text/javascript" >
   
    //表单提交检测
    function checkform() {
       var give_type = $("input[name='give_type']:checked").val();
       var money = $.trim($("#money").val());
       var begin_time = $.trim($("#begin_time").val());
       var end_time = $.trim($("#end_time").val());
       var level_ids = $("input[name='level_ids[]']:checked").val();
       var member_list = $.trim($("#member_list").val());
       if(give_type == "level") {
           if(level_ids == undefined) {
               alert("请至少选择一个会员等级！");
               return false;
           }
       } else if (give_type == "single") {
           if(member_list == "") {
               alert("请至少填写一个会员！");
               $("#member_list").focus();
               return false;
           }
       } else if (money == "") {
           alert("请填写优惠券面值！");
           $("#money").focus();
           return false;
       } else if(!isNumber(money)) {
           alert("优惠券面值必须为数字！");
           $("#money").focus();
           return false;
       } else if (begin_time == "") {
           alert("请填写开始使用时间！");
           $("#begin_time").focus();
           return false;
       } else if (end_time == "") {
           alert("请填写结束使用时间！");
           $("#end_time").focus();
           return false;
       } 
    }
</script>
